package se.chalmers.tda366.crumble.gui.dialogs;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import se.chalmers.tda366.crumble.gui.utils.CloseActionListener;
import se.chalmers.tda366.crumble.gui.utils.GuiObserv;
import se.chalmers.tda366.crumble.resources.Constants;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class AddCategoryView extends JPanel {
	
	public AddCategoryView(){
		initGUI();
	}

	private void initGUI() {
		try {
			this.setLayout(null);
			this.setPreferredSize(new java.awt.Dimension(390, 151));
			this.setSize(390, 151);
			{
				categoryNameTextField = new JTextField();
				this.add(categoryNameTextField, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
				categoryNameTextField.setBounds(216, 54, 161, 22);
			}
			{
				categoryNameLabel = new JLabel();
				this.add(categoryNameLabel, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
				categoryNameLabel.setText("Name of new category:");
				categoryNameLabel.setBounds(79, 57, 157, 15);
			}
			{
				addCategoryButton = new JButton();
				this.add(addCategoryButton, new GridBagConstraints(3, 2, 1, 2, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
				addCategoryButton.setText("Add");
				addCategoryButton.setBounds(321, 88, 58, 27);
				addCategoryButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						GuiObserv.getInstance().fireNotify(((JButton)evt.getSource()).getParent(), Constants.Actions.ADD_CATEGORY);
					}
				});
			}
			{
				cancelNewCategoryButton = new JButton();
				this.add(cancelNewCategoryButton, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
				cancelNewCategoryButton.setText("Cancel");
				cancelNewCategoryButton.setBounds(242, 88, 68, 27);
				cancelNewCategoryButton.addActionListener(new CloseActionListener());
			}
			{
				addNewCategoryLabel = new JLabel();
				this.add(addNewCategoryLabel);
				addNewCategoryLabel.setText("Add a new category...");
				addNewCategoryLabel.setBounds(79, 12, 318, 33);
				addNewCategoryLabel.setFont(se.chalmers.tda366.crumble.resources.Constants.HEADLINEFONT);
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	public String getCategory(){
		return categoryNameTextField.getText();
	}
	
	private JTextField categoryNameTextField;
	private JButton cancelNewCategoryButton;
	private JLabel addNewCategoryLabel;
	private JButton addCategoryButton;
	private JLabel categoryNameLabel;

}
